/**
 * @param {number[][]} bombs
 * @return {number}
 */
 var maximumDetonation = function(bombs) {
  const g = {}
  for(let i = 0; i<bombs.length; i++){
    let [x1, y1, r1] = bombs[i]
    g[i] = g[i] || []
    for(let j = i+1; j<bombs.length; j++){
      g[j] = g[j] || []
      let [x2, y2, r2] = bombs[j]
      let len = Math.sqrt((x1-x2)**2 + (y1-y2)**2)
      let max = Math.max(r1, r2), min = Math.min(r1, r2)
      if(len <= min){
        g[i].push(j)
        g[j].push(i)
      }
      else if(len <= max){
        if(max === r1) g[i].push(j)
        if(max === r2) g[j].push(i)
      }
    }
  }
  for(let i = 0; i<bombs.length; i++){
    let arr = []
    let q = [i], used = new Set().add(i)
    while(q.length){
      let temp = []
      for(let x = q.length-1; x>=0; x--){
        let c = q.pop()
        for(let j of g[c]){
          if(!used.has(j)){
            temp.push(j)
            arr.push(j)
            used.add(j)
          }
        }
      }
      q = temp
    }
    g[i].push(...arr)
  }
  let ans = 0
  for(let v of Object.values(g)){
    ans = Math.max(ans, new Set(v).size+1)
  }
  return ans
};
